"use strict";
/**
 * @param bytes {Array<number>}
 * @returns {string}
 */
function toStr(bytes) {
    var result = [], i = 0;
    while (i < bytes.length) {
        var c = bytes[i];
        if (c < 128) {
            result.push(String.fromCharCode(c));
            i++;
        } else if (c > 191 && c < 224) {
            result.push(String.fromCharCode(((c & 0x1f) << 6) | (bytes[i + 1] & 0x3f)));
            i += 2;
        } else {
            result.push(String.fromCharCode(((c & 0x0f) << 12) | ((bytes[i + 1] & 0x3f) << 6) | (bytes[i + 2] & 0x3f)));
            i += 3;
        }
    }
    return result.join('');
}
/**
 * @param text {string}
 * @returns {Array}
 */
function toBytes(text){
    var result = [], i = 0;
    text = encodeURI(text);
    while (i < text.length) {
        var c = text.charCodeAt(i++);
        // if it is a % sign, encode the following 2 bytes as a hex value
        if (c === 37) {
            result.push(parseInt(text.substr(i, 2), 16));
            i += 2;
            // otherwise, just the actual byte
        } else {
            result.push(c)
        }
    }
    return result;
}
module.exports = {toStr,toBytes};
